//
//  DrawCircleDemo.swift
//  firstProject
//
//  Created by 张彦辉 on 2017/4/23.
//  Copyright © 2017年 张彦辉. All rights reserved.
//

import UIKit

class DrawCircleDemo: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        let drawCircle = DrawCircle(frame: self.view.frame)
        self.view.addSubview(drawCircle)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}


class DrawCircle: UIView {
    override func draw(_ rect: CGRect) {
        self.backgroundColor = UIColor.yellow
        guard let context = UIGraphicsGetCurrentContext() else {
            print("Error")
            return
        }
        
        //设置线条颜色
        context.setStrokeColor(UIColor.red.cgColor)
        //设置线条宽度
        let strokeWidth: CGFloat = 3.0
        context.setLineWidth(strokeWidth)
        
        //设置中心点
        let center = CGPoint(x: self.frame.midX, y: self.frame.midY)
        //设置半径
        let radius = self.frame.midX - strokeWidth
        
        //设置起点角度
        let startAngle: CGFloat = 0.0
        //设置终点角度
        let endAngle = 2 * CGFloat.pi
        
        context.addArc(center: center, radius: radius, startAngle: startAngle, endAngle: endAngle, clockwise: true)
        context.drawPath(using: .stroke)
        
    }
}
